/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.escom.administracion.dao.hibernate;

import com.escom.administracion.dao.AlumnoDAO;
import com.escom.administracionperfiles.hbm.dto.Alumno;
import com.escom.cliente.exception.DAOException;
import com.escom.hibernate.template.AdminSoportHibernate;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author yamil
 */
public class AlumnoDAOHBM extends AdminSoportHibernate implements AlumnoDAO,Serializable{

    @Override
    public void create(Alumno alumno) throws DAOException {
         save(alumno);
    }

    @Override
    public void edit(Alumno alumno) throws DAOException {
        update(alumno);
    }

    @Override
    public void remove(Alumno alumno) throws DAOException {
        delete(alumno);
    }

    @Override
    public Alumno find(Object id) throws DAOException {
       return  (Alumno) findByPrimaryKey(Alumno.class,id);
    }

    @Override
    public List<Alumno> findAll() throws DAOException {
        return findAll(Alumno.class);
    }

    @Override
    public int count() {
        return count();
    }

    @Override
    public Alumno findAlumnoByBoletaAndPassword(Integer boleta, String password) throws DAOException {
        Alumno alumno=null;
        Criteria criteria = getSession().createCriteria(Alumno.class);
        criteria.add(Restrictions.and(Restrictions.eq("contrasenia", password), Restrictions.eq("boleta", boleta))).setMaxResults(1);
        if(!criteria.list().isEmpty())
        alumno=(Alumno)criteria.list().get(0);
        return alumno;
    }

    @Override
    public boolean findAlumnoByBoletaAndCorreo(Integer boleta, String correo) throws DAOException {
        Alumno alumno=null;
        Session session = getSession();
        Criteria criteria = getSession().createCriteria(Alumno.class);
        criteria.add(Restrictions.and(Restrictions.eq("correo", correo), Restrictions.eq("boleta", boleta))).setMaxResults(1);
        if(!criteria.list().isEmpty())
        alumno=(Alumno)criteria.list().get(0);
        session.close();
        return alumno!=null?true:false;
        
    }

}
